<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      margin: 100px auto 0;
      width: 500px;
      height: 260px;
      background-color: tan;
    }
  </style>
</head>

<body>
  <div class="box" id="oBox"></div>
  <script>
    // 防抖
    const debounce = (callback, time) => {
      let timer = null
      return function() {
        clearTimeout(timer)
        timer = setTimeout(() => {
          callback.call(this, ...arguments)
        }, time)
      }
    };
    oBox.onmousemove = debounce(function (e) {
      let disX = e.pageX - this.offsetLeft;
      let disY = e.pageY - this.offsetTop
      this.innerHTML = `${disX} ${disY}`
    }, 1000);
  </script>
</body>

</html>
